package C7_1_ComposedMethod.before;

/**
 * @author xufy
 * @version 1.0
 **/
public class ListDemo {
    boolean readOnly;
    int size = 3;
    Object[] elements = {1, 2, 3};

    public void add(Object element) {
        if (!readOnly) {
            int newSize = size + 1;
            if (newSize > elements.length) {
                Object[] newElements = new Object[elements.length + 10];
                for (int i = 0; i < size; i++) {
                    newElements[i] = elements[i];
                }
                elements = newElements;
            }
            elements[size++] = element;
        }
    }


}
